<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <head th:include="commom::title('门诊管理系统')"></head>
</head>

<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <!-- 表 格 信 息 -->
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>


    </div>
</div>
<script th:src="@{/static/lib/layui-v2.5.5/layui.js}" charset="utf-8"></script>
<script>
    layui.use(['form', 'table','layer','laypage'], function () {
        const $ = layui.jquery,
            form = layui.form,
            layer = layui.layer,
            table = layui.table;

        table.render({
            elem: '#currentTableId',
            url: '/root/reservation',
            limits: [3, 5, 10, 20],
            limit: 10,
            page: true,
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print'],
            cols: [
                [
                {type: "checkbox", field: 'center'},
                {field: 'doctor_id', width: 100, title: '医生ID', sort: true, align:'center'},
                {field: 'doctor_name', width: 120, title: '医生名字', align:'center'},
                {field: 'patient_id', width: 100, title: '病人ID', sort: true, align:'center'},
                {field: 'patient_name', width: 120, title: '病人名字', align:'center'},
                {field: 'period_id', width: 100, title: '时段ID', align:'center'},
                {field: 'start_time', width: 150, title: '开始时间', align:'center'},
                {field: 'end_time', width: 150, title: '结束时间', align:'center'},
                ]
            ],
            id: 'testReload'
        });


        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['600px', '70%'],
                    content: '/view/modifyHealth?id='+data.id,
                });
                return false;

            } else if (obj.event === 'delete') {
                layer.confirm('确定删除行？', function (index) {
                    del(data.id,obj,index);
                });
            }
        });

        function del(id,obj,index){
            $.ajax({
                url:'/root/delHealth?id='+id,
                dataType:'json',
                type:'post',
                success:function (data) {
                    obj.del();
                    layer.msg(data.msg,{icon: 1,time: 1000});
                    layer.close(layui.index);
                    table.reload('testReload');
                }
            })
        }





    });
</script>

</body>
</html>
